<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="https://cdn.bootcss.com/socket.io/2.1.0/socket.io.js"></script>

    <script >

        var username = 'username';
        var socket = io.connect('http://192.168.0.101:9092?no=' + username);

        socket.on('connect', function () {
            console.log('连接')
        });

        socket.on('runningTask', function (data) {
            console.log("收到全服数据")
            console.log(data);
        });


        socket.on('taskResult', function (data) {
            console.log("收到个人数据")
            console.log(data);

        });



        function clickme(){
            // 可以是任意类型的数据，这里用了一个json对象，后端有对应的实体类
            var jsonObject = {
                "username": "username1",
                "to": 2
            };
            socket.emit('messageevent', jsonObject);
        }

        socket.on('disconnect', function () {
            console.log("断开")
        });

    </script>
</head>
<body>

<button id="btn" onclick="clickme()">click me</button>
</body>
</html>